<!-- 选择买号弹窗 -->

<style>
.DialogMain { width:660px;}
.DialogItem { width:660px; height:300px; overflow:auto; border:1px solid #F5F5F5; padding-left:5px;}
.DialogItem li { display:inline-block; margin:3px 2px;; font-family: "微软雅黑",Tahoma,sans-serif;font-size: 14px;}
.DialogItem li.buyer-nick { width:180px; color:#FF4400; white-space:nowrap;}
.DialogItem li.buyer-nick a { width:150px; color:#F52B00;}
.DialogItem li.buyer-nick a:hover { text-decoration:underline;}
.DialogItem li div.buyer-realname { width:30px; height:16px; display:inline-block; background:#00BA97; color:#FFF; border-radius:3px; font-size:12px; font-family:宋体; text-align:center; line-height:16px;}
.bd-buyer-bt { width:105px; height:36px; background:#FF4400; cursor:pointer; border:none; color:#FFF; border-radius:18px; font-family:Microsoft YaHei; font-size:13px;}
.bd-buyer-bt:hover { background:#F82800;}
.sel-buyer-bt { width:100px; height:35px; background:#428BCA; cursor:pointer; border:none; color:#FFF; border-radius:5px; margin-left:425px;}
.sel-buyer-bt:hover { background:#3276B1;}
.rank-tips { display:inline-block; float:right; color:#F52B00; font-size:16px; font-weight:bold;}
</style>


<div class="DialgoMain">
    <div>
        <em id="rankLimit" style="display:none;"><img src="images/icon/sk-13.png" title="买号等级要求"/></em>
        <em id="realName" style="display:none;"><img src="images/icon/sk-01.png" title="买号实名认证"/></em>
        <em id="checkBuyerIp" style="display:none;"><img src="images/icon/sk-11.png" title="过滤ip"/></em>
        <em id="takeArea" style="display:none;"><img src="images/icon/sk-12.png" title="限定省份"/></em>
        <em id="checkTaker" style="display:none;"><img src="images/icon/sk-02.png" title="审核接单人"/></em>
        <em id="compare" style="display:none;"><img src="images/icon/sk-03.png" title="货比三家"/></em>
        <em id="browseOthers" style="display:none;"><img src="images/icon/sk-04.png" title="浏览店铺宝贝"/></em>
        <em id="collect" style="display:none;"><img src="images/icon/sk-05.png" title="收藏宝贝"/></em>
        <em id="stayTime" style="display:none;"><img src="images/icon/sk-06.png" title="付款前停留时间"/></em>
        <em id="talk" style="display:none;"><img src="images/icon/sk-07.png" title="付款前需旺旺聊天"/></em>
        <em id="browseFoot" style="display:none;"><img src="images/icon/sk-08.png" title="浏览到宝贝详情页底部"/></em>
        <em id="address" style="display:none;"><img src="images/icon/sk-09.png" title="规定收货地址"/></em>
        <em id="ratePic" style="display:none;"><img src="images/icon/sk-14.png" title="评价晒图"/></em>
        <em id="rateSuccessPic" style="display:none;"><img src="images/icon/sk-10.png" title="5分好评截图"/></em>
        <div id="buyer-tips" class="rank-tips">要求：<img id="rank-img" title="买号等级要求"/></div>
    </div>
    <div>
        <p id="sel-buyer-tips" style="font-size:18px; font-weight:bold; margin:10px 0;">请选择一个买号接单</p>
        <div class="DialogItem">
            <!--<p>
                <li class="buyer-nick">
                	<label style="white-space:nowrap;">
                		<input type="radio" name="buyer"/>&nbsp;西门吹雪
                    </label>
                </li>
                <li style="width:50px;"><div class="buyer-realname">实名</div></li>
                <li style="white-space:nowrap;">（淘宝信用：106，本周已接：0，今日已接：0）</li> 
            </p>-->
        </div>
    </div>
    <div style="margin-top:10px;">
        <input type="button" class="bd-buyer-bt" value="+&nbsp;绑定买号"
        	onClick="window.open('bind-buyer.html','_blank')" />
        <input type="button" class="sel-buyer-bt" value="确定接单" onclick="selBuyer()" />
    </div>
</div>


<script>
	
	var orderType = ShowTaskData.taskObj.orderType;
	getAvaBuyers(ShowTaskData.taskId);
	
	if(ShowTaskData.taskObj.checkBuyerIp)			$("#checkBuyerIp").show();
	if(ShowTaskData.taskObj.takeArea)				$("#takeArea").show();
	if(ShowTaskData.taskObj.rankLimit >= 1)			$("#rankLimit").show();
	if(ShowTaskData.taskObj.realName)				$("#realName").show();
	if(ShowTaskData.taskObj.checkTaker)				$("#checkTaker").show();
	if(ShowTaskData.taskObj.compare)				$("#compare").show();
	if(ShowTaskData.taskObj.browseOthers)			$("#browseOthers").show();
	if(ShowTaskData.taskObj.collect)				$("#collect").show();
	if(ShowTaskData.taskObj.stayTime)				$("#stayTime").show();
	if(ShowTaskData.taskObj.talk)					$("#talk").show();
	if(ShowTaskData.taskObj.browseFoot)				$("#browseFoot").show();
	if(ShowTaskData.taskObj.address)				$("#address").show();
	if(ShowTaskData.taskObj.ratePic)				$("#ratePic").show();
	if(ShowTaskData.taskObj.rateSuccessPic)			$("#rateSuccessPic").show();
	
	if(ShowTaskData.taskObj.rankLimit >= 1 || ShowTaskData.taskObj.realName) {
		if(ShowTaskData.taskObj.rankLimit == 0) {
			$("#rank-img").prop("src", "images/buyer/rank_-1.png");
		} else if(ShowTaskData.taskObj.rankLimit == 11) {
			$("#rank-img").prop("src", "images/buyer/rank_11.png");
			$("#sel-buyer-tips").text("请选择一个不低于1心的买号接单");
		} else if(ShowTaskData.taskObj.rankLimit == 12 || ShowTaskData.taskObj.rankLimit == 1) {
			$("#rank-img").prop("src", "images/buyer/rank_12.png");
			$("#sel-buyer-tips").text("请选择一个不低于2心的买号接单");
		} else if(ShowTaskData.taskObj.rankLimit == 13) {
			$("#rank-img").prop("src", "images/buyer/rank_13.png");
			$("#sel-buyer-tips").text("请选择一个不低于3心的买号接单");
		} else if(ShowTaskData.taskObj.rankLimit == 14 || ShowTaskData.taskObj.rankLimit == 2) {
			$("#rank-img").prop("src", "images/buyer/rank_14.png");
			$("#sel-buyer-tips").text("请选择一个不低于4心的买号接单");
		} else if(ShowTaskData.taskObj.rankLimit == 15) {
			$("#rank-img").prop("src", "images/buyer/rank_15.png");
			$("#sel-buyer-tips").text("请选择一个不低于5心的买号接单");
		} else if(ShowTaskData.taskObj.rankLimit == 21 || ShowTaskData.taskObj.rankLimit == 3) {
			$("#rank-img").prop("src", "images/buyer/rank_21.png");
			$("#sel-buyer-tips").text("请选择一个不低于1钻的买号接单");
		}
//		if(ShowTaskData.taskObj.realName) {
//			$("#buyer-tips").append("实名");
//		}
	}
	
	var buyerListSize = 0;
	
	/*
	获取可用的买号
	*/
	function getAvaBuyers(taskId) {
		var param = {
			taskId: taskId,
			orderType: orderType,
		};
		AQ.callAQ("filterBuyer.do", param, function(result) {
			buyerListSize = result[0].count;
			if(buyerListSize == 0) {
				$(".DialogItem").append("<p style='color:#F70217; font-size:20px; font-weight:bold; margin:20px;'>没有可用的买号，赶紧绑定几个吧！或者换个任务试试。^_^</p>");
			}
			for(var i = 1; i < result.length; ++i) {
				var buyerId = result[i].buyerId;
				var buyerNick = result[i].buyerNick;
				var isRealName = result[i].isRealName;
				var buyerRank = result[i].buyerRank;
				var dayTake = result[i].dayTake;
				var weekTake = result[i].weekTake;
				var monthTake = result[i].monthTake;
				var note = result[i].note;
				
				var realNameHtml = '<img src="images/buyer/real_name_'+ isRealName +'.png">';
				var buyerRankHtml = '<img src="images/buyer/rank_'+ buyerRank +'.png">';
				
				var buyerHtml = '<p>'+
					'<li class="buyer-nick">'+
						'<input type="radio" name="buyer" value="'+ buyerId +'"/>&nbsp;'+						
						'<a href="http://www.kehuda.com/g/x/#username='+buyerNick+'" target="_blank">'+buyerNick+'</a>'+
					'</li>'+
					'<li style="width:50px;">'+ realNameHtml +'</li>'+
					'<li style="width:150px;">（等级：'+ buyerRankHtml +'</li>'+
					'<li style="white-space:nowrap;">日/周/月接单量：'+ dayTake +' / '+ weekTake +' / '+ monthTake +'）</li>' +
					'<li style="width:80px; font-size:12px; color:#D4D2C6;">'+ note +'</li>'+
				'</p>';
				$(".DialogItem").append(buyerHtml);
			}
		}, function(err, code) {
			var content = "<p style='color:#F70217; font-size:20px; font-weight:bold; margin:20px;'>"+ err +"</p>";
			if(err.indexOf("身份认证") >= 0) {
				content += '<a href="identity.html" target="_blank" style="color:#F70217; font-size:18px; font-weight:bold; margin:20px; text-decoration:underline;">提交身份认证</a>';
				setTimeout(function() { location.replace("identity.do"); }, 2*1000);
			}
			$(".DialogItem").append(content);
		});
	}
	
	/* 选择买号 */
	function selBuyer() {
		if(buyerListSize == 0) {
			$(".ui-dialog").each(function(index, element) {
				$(element).parent("div").remove();
			});
			$(".ui-popup-backdrop").each(function(index, element) {
				$(element).remove();
			});
			return;
		}
		var buyerId = $("input[name='buyer']:checked").val();
		if(typeof(buyerId) == "undefined") {
			Utils.msgDialog("请选择一个买号！");
			return;
		}
		
		var param = {
			taskId: ShowTaskData.taskId,
			buyerId: buyerId,
			orderType: orderType,
		};
		AQ.callAQ("chooseBuyer.do", param, function(result) {
			var url = orderType == 1 ? "taked-task.html" : "taked-task-visit.html";
			location.replace(url);
		}, function(err, code){
			Utils.msgDialog('<span style="color:#F70217; font-size:16px; font-weight:bold;">'+ err +'</span>');
		});
	}

</script>